package com.bjbn.service;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;

@Service
public class KafkaMapSender {

    private final KafkaTemplate<String, String> kafkaTemplate;
    private final ObjectMapper objectMapper;

    public KafkaMapSender(KafkaTemplate<String, String> kafkaTemplate, ObjectMapper objectMapper) {
        this.kafkaTemplate = kafkaTemplate;
        this.objectMapper = objectMapper;
    }

    public void sendMap(String topic, Map<String, String> dataMap) throws JsonProcessingException {
        String jsonData = objectMapper.writeValueAsString(dataMap);
        kafkaTemplate.send(topic, jsonData);
    }
}